#!/bin/bash

#------------------------------------------------------------------------------
#Filename:	75345-nfs.sh
#Version:	1.1
#Date:		2013/11/20
#Author:	yuanhui.shi
#Email:		yuanhui.shi@cs2c.com.cn
#Summary:	02.04网络服务-05NFS-01字符模式-09nfsstat-01查看挂载的NFS文件系统信息
#Notes:		NFS服务配置——nfsstat命令查看挂载信息
#Copyright:	China Standard Software Co.,Ltd.
#History:
#		Version 1.0,2013/11/20
#		-The first one
#-----------------------------------------------------------------------------


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

source ../../../lib/Echo.sh
source ./lib/Ssh.sh
source ../../../lib/XmlParse.sh
source ./lib/cmd.sh

function CleanData ()
{
  umount -f /mnt &>/dev/null
  EchoInfo "关闭服务器端的nfs服务，删除共享目录"
  Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "command -v systemctl && /bin/systemctl stop nfs.service || /sbin/service nfs stop"
  Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "rm -rf /nfs-test"
  Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "echo '' >/etc/exports"
  EchoInfo "75345-nfs.sh执行完毕"
}

trap "CleanData" EXIT INT
if [ -z "$SFROOT" ]
then
    echo "SFROOT is null"
    exit 1
fi

DATA_DIR="${SFROOT}/testcases/Network_Service"
DATA_FILE="config.xml"

XmlParse ${DATA_DIR}/${DATA_FILE}

GetValue ServerIP ReHost
GetValue USER UserName
GetValue PASSWORD RootPasswd


#DATA_DIR="./data"
#DATA_FILE="75345-nfs.xml"
#
#XmlParse ${DATA_DIR}/${DATA_FILE}
#
#GetValue USER USER
#GetValue ServerIP ServerIP
#GetValue PASSWORD PASSWORD

#远程配置服务器
EchoInfo "远程配置服务器${ServerIP}"

Scp "${USER}" "${ServerIP}" "${PASSWORD}" "./nfs-config.sh" "/root/"

Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "echo '/nfs-test *(rw)'>/etc/exports"

Ssh "${USER}" "${ServerIP}" "${PASSWORD}" "sh nfs-config.sh"

Ssh "${USER}" "${ServerIP}" "${PASSWORD}"  "rm -rf /root/nfs-config.sh"

#客户端是否可以查看到nfs共享目录
EchoInfo "客户端能否看见nfs共享目录"
stop_daemon iptables  

test -n "`showmount -e ${ServerIP} |grep /nfs-test`" 
EchoResult "客户端可以看见nfs共享目录"

# check if already mounted
mount | grep ${ServerIP}:/nfs-test | grep /mnt
[ $? -eq 0 ] && umount -f /mnt

EchoInfo "客户端挂载共享目录"
mount ${ServerIP}:/nfs-test/ /mnt
#查看当前挂载的NFS文件系统信息
EchoInfo "查看当前挂载的NFS文件系统信息"
test -n "`nfsstat -m |grep  "${ServerIP}:/nfs-test"`"
EchoResult "可以通过nfsstat命令查看当前挂载的NFS文件系统信息"


